package com.foreveross.vo.common;

import java.util.List;

import com.foreveross.common.Constants;

public class PageVo<T> {
	//总页数
	private int countPage;
	//总数记录数
	private int total;
	//当前页
	private int currentPage = 1;
	//数据
	private List<T> rows = null;
	//数据
	private List<T> data = null;
		
	//每页数据量
	private int pageSize = Constants.PAGE_SIZE;
	//开始下标
	private int pageIndex;

	public PageVo() {
	}
	
	public void init(int currentPage, int pageSize) {
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		calculate();
	}

	public PageVo(String currentPage, int total) {
		if(null != currentPage && !"".equals(currentPage))
		this.currentPage = Integer.parseInt(currentPage);
		this.total = total;
		calculate();
	}

	public PageVo(String currentPage, int total, String pageSize) {
		super();
		if(null != currentPage && !"".equals(currentPage))
		this.currentPage = Integer.parseInt(currentPage);
		this.total = total;
		if(null != pageSize && !"".equals(pageSize))
		this.pageSize = Integer.parseInt(pageSize);;
		calculate();
	}
	

	private void calculate() {
		// 计算开始索引
		this.pageIndex = (currentPage - 1) * pageSize;
		// 计算总页数
		this.countPage = (total % pageSize == 0) ? (total / pageSize)
				: (total / pageSize + 1);
	}

	public int getCountPage() {
		return countPage;
	}

	public int gettotal() {
		return total;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	 

	public int getpageSize() {
		return pageSize;
	}

	public int getpageIndex() {
		return pageIndex;
	}

	public void setCountPage(int countPage) {
		this.countPage = countPage;
	}

	public void settotal(int total) {
		this.total = total;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	 

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public List<T> getRows() {
		return rows;
	}
	
	public void setRows(List<T> rows) {
		this.rows = rows;
	}

}
